package com.chenyue.cm.api.station;

import com.chenyue.cm.bean.Success;
import com.chenyue.cm.station.domain.JdStation;
import com.chenyue.cm.station.service.JdStationApplyService;
import com.chenyue.cm.station.service.JdStationService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author: ljy
 * @Title: ApiStationController
 * @Description: 场馆Api
 * @Date: 2021-07-23
 */
@RestController
@RequestMapping("/api/station")
@Api(value = "场馆api", tags = "场馆api")
@ApiSort(6)
public class ApiStationController {

    private final JdStationService jdStationService;
    private final JdStationApplyService jdStationApplyService;

    public ApiStationController(JdStationService jdStationService, JdStationApplyService jdStationApplyService) {
        this.jdStationService = jdStationService;
        this.jdStationApplyService = jdStationApplyService;
    }

    /**
     * 根据场馆id获取场馆详情
     *
     * @param stationId 场馆id
     * @return Success
     */
    @PostMapping("/getStationInfo")
    @ApiOperation(value = "单个场馆详情", notes = "单个场馆详情")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "场馆id", name = "stationId", dataType = "int", required = true),
    })
    public Success getStationInfo(Integer stationId) {
        JdStation station = jdStationService.getById(stationId);
        return Success.success(station);
    }

    /**
     * 预约场馆
     *
     * @param stationId 场馆id
     * @param userId    用户id
     * @param applyTime 预约时间
     * @return Success
     */
    @PostMapping("/applyStation")
    @ApiOperation(value = "用户预约场馆", notes = "用户预约场馆")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "场馆id", name = "stationId", dataType = "int", required = true),
            @ApiImplicitParam(value = "用户id", name = "userId", dataType = "int", required = true),
            @ApiImplicitParam(value = "预约到馆时间（yyyy-MM-dd HH:mm:ss）", name = "applyTime", dataType = "Date", required = true),
    })
    public Success applyStation(Integer stationId, Integer userId, Date applyTime) {
        int success = jdStationApplyService.applyStation(stationId, userId, applyTime);
        return success > 0 ? Success.success() : Success.error();
    }
}
